<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : Bypass</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">
  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName">Bypass</p>
    	
    	
       <p class="linkListHeader">Methods</p>
       <p class="linkList">
           
    <a href="bypass_method_activate.html" title="Activate the bypass functionality. In other words, the wrapped UGen will NOT
 have an effect on the UGen patched to this Bypass.">activate ( )</a><br/>
    
    <a href="bypass_method_channelcount.html" title="Returns the number of channels this UGen has been configured to generate.">channelCount ( )</a><br/>
    
    <a href="bypass_method_deactivate.html" title="Deactivate the bypass functionality. In other words, the wrapped UGen WILL 
 have an effect on the UGen patched to this Bypass, as if it was in the 
 signal chain in place of this Bypass.">deactivate ( )</a><br/>
    
    <a href="bypass_method_getlastvalues.html" title="Return the last values generated by this UGen. This will most often be
 used by sub-classes when pulling data from their inputs.">getLastValues ( )</a><br/>
    
    <a href="bypass_method_isactive.html" title="Find out if this Bypass is active or not.">isActive ( )</a><br/>
    
    <a href="bypass_method_patch.html" title="Send the output of this UGen to another UGen, UGenInput, or AudioOutput.">patch ( )</a><br/>
    
    <a href="bypass_method_printinputs.html" title="Prints all inputs connected to this UGen (for debugging)">printInputs ( )</a><br/>
    
    <a href="bypass_method_samplerate.html" title="Returns the sample rate of this UGen.">sampleRate ( )</a><br/>
    
    <a href="bypass_method_setchannelcount.html" title="Let this UGen know how many channels of audio you will be asking it for.">setChannelCount ( )</a><br/>
    
    <a href="bypass_method_setsamplerate.html" title="Set the sample rate for this UGen.">setSampleRate ( )</a><br/>
    
    <a href="bypass_method_tick.html" title="Generates one sample frame for this UGen.">tick ( )</a><br/>
    
    <a href="bypass_method_ugen.html" title="Retrieve the UGen that this Bypass is wrapping.">ugen ( )</a><br/>
    
    <a href="bypass_method_unpatch.html" title="Unpatch this UGen from an AudioOutput or other UGen.">unpatch ( )</a><br/>
    
	   </p>
   
    </td>
    <td class="mainText border-left">
    	<p>
 The Bypass UGen allows you to wrap another UGen and then insert that UGen into your
 signal chain using Bypass in its place. You can then dynamically route the 
 audio through the wrapped UGen or simply allow incoming audio to pass through unaffected. 
 Using a Bypass UGen allows you to avoid concurrency issues caused by patching and unpatching 
 during runtime from a Thread other than the audio one.
 </p>
 <p>
 Your usage of Bypass might look something like this:
 </p>
 <pre>
 Bypass&lt;GranulateSteady&gt; granulate = new Bypass( new GranulateSteady() );
 filePlayer.patch( granulate ).patch( mainOut );
 </pre>
 <p>
 If you needed to patch something else to one of the inputs of the GranulateSteady,
 you'd use the <code>ugen</code> method of Bypass to retrieve the wrapped UGen
 and operate on it:
 </p>
 <pre>
 grainLenLine.patch( granulate.ugen().grainLen );
 </pre>
 <p>
 Now, calling the <code>activate</code> method will <em>bypass</em> the granulate effect 
 so that the Bypass object outputs the audio that is coming into it. Calling the 
 <code>deactivate</code> method will route the audio through the wrapped effect. The 
 <code>isActive</code> method indicates whether or not the wrapped effect is currently 
 being bypassed.
 </p>
    	<p class="memberSectionHeader">Constructors</p>
    	<pre><em>Construct a Bypass UGen that wraps a UGen of type T.</em>
Bypass(UGen ugen)
</pre>
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">ugen</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">the UGen that this can bypass</span><br/>
    
   
    	<p class="memberSectionHeader">Related</p>
    	<A href="ugen_class_ugen.html">UGen</A><BR>

    	<p class="memberSectionHeader">Example</p>
    	<pre>/* bypassExample&lt;br/>
 * is an example of using the Bypass UGen in a continuous sound example.
 * Press the space bar to activate and deactivate the Bypass.
 * &lt;p>
 * For more information about Minim and additional features, 
 * visit http://code.compartmental.net/minim/
 * &lt;p>
 * author: Anderson Mills&lt;br/>
 * Anderson Mills's work was supported by numediart (www.numediart.org)
 */

// import everything necessary to make sound.
import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
Minim         minim;
AudioOutput   out;
// the type in the angle brackets lets the program
// know the type that should be returned by the ugen method of Bypass
Bypass&lt;Delay> bypassedDelay;

// setup is run once at the beginning
void setup()
{
  // initialize the drawing window
  size( 512, 200, P2D );

  // initialize the minim and out objects
  minim = new Minim(this);
  out = minim.getLineOut( Minim.MONO, 2048 );
  
  // initialize myDelay with continual feedback and no audio passthrough
  Delay myDelay = new Delay( 0.6, 0.9, true, true );
  
  // create a Bypass to wrap the Delay so we can turn it on and off
  bypassedDelay = new Bypass&lt;Delay>( myDelay );
  
  // create the Blip that will be used
  Oscil myBlip = new Oscil( 245.0, 0.3, Waves.saw( 15 ) );
  
  // create an LFO to be used for an amplitude envelope
  Oscil myLFO = new Oscil( 1, 0.3, Waves.square( 0.95 ) );
  // offset the center value of the LFO so that it outputs 0 
  // for the long portion of the duty cycle
  myLFO.offset.setLastValue( 0.3f );

  myLFO.patch( myBlip.amplitude );
  
  // and the Blip is patched through the Bypass into the Summer.
  myBlip.patch( bypassedDelay ).patch( out );
}

// draw is run many times
void draw()
{
  // erase the window to dark grey
  background( 64 );
  // draw using a light gray stroke
  stroke( 192 );
  // draw the waveforms
  for( int i = 0; i &lt; out.bufferSize() - 1; i++ )
  {
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }  
  
  if ( bypassedDelay.isActive() )
  {
    text( "The Delay effect is bypassed.", 10, 15 );
  }
  else
  {
    text( "The Delay effect is active.", 10, 15 );
  } 
}

void keyPressed()
{
  if ( key == ' ' )
  {
    if ( bypassedDelay.isActive() ) 
    {
      bypassedDelay.deactivate();
    }
    else
    {
      bypassedDelay.activate();
    }
  }
}

// when the mouse is moved, change the delay parameters
void mouseMoved()
{
  // set the delay time by the horizontal location
  float delayTime = map( mouseX, 0, width, 0.0001, 0.5 );
  bypassedDelay.ugen().setDelTime( delayTime );
  
  // set the feedback factor by the vertical location
  float feedbackFactor = map( mouseY, 0, height, 0.0, 0.99 );
  bypassedDelay.ugen().setDelAmp( feedbackFactor );
}
</pre>
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>